import dao.PatientDao;
import dao.PrescriptionDao;
import dao.impl.PatientDaoImpl;
import dao.impl.PrescriptionDaoImpl;
import entity.Patient;
import utils.ConnectionUtil;
import vo.PrescriptionCheckItemDepartmentVo;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Scanner;

/**
 * @projectName: Hospital
 * @package: PACKAGE_NAME
 * @className: Test7
 * @author: 翟
 * @date: 2025/4/1 11:32
 */

public class Test7 {

    static Scanner input = new Scanner(System.in);

    /**
     * 完成输出病人检查记录的功能，输出当前登录病人的信息
     */
    public static void main(String[] args) {
        Connection conn = null;
        try {
            conn = ConnectionUtil.getConnection();
            Patient patient = doLogin(conn);
            do {
                System.out.println("1.查看检查记录 2.查看病人信息 3.修改病人信息 0.退出");
                int choice = input.nextInt();

                switch (choice) {
                    case 1:
                        getPrescriptionCheckRecord(conn , patient.getPatientId());
                        break;
                    case 2:
                        System.out.println(patient);
                        break;
                    case 3:
                        break;
                    case 0:
                        System.exit(0);
                }
            }while (true);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            ConnectionUtil.closeALL(null , null , conn);
        }
    }

    public static Patient doLogin(Connection conn) throws SQLException {
        System.out.println("用户登录");
        System.out.println("请输入身份证号码：");
        String identityNum = input.nextLine();
        System.out.println("请输入密码：");
        String password = input.nextLine();
        PatientDao patientDao = new PatientDaoImpl(conn);
        Patient patient = patientDao.getPatientByIdentityNumAndPassword1(identityNum , password);
        if (patient != null){
            System.out.println("用户"+patient.getPatientName()+"登录成功");
            return patient;
        }else {
            System.out.println("账号或密码输入有误！！！");
            return doLogin(conn);
        }
    }

    //查询病人对应处方检查记录
    public static void getPrescriptionCheckRecord(Connection conn , int patientId) throws SQLException {
        PrescriptionDao prescriptionDao = new PrescriptionDaoImpl(conn);
        List<PrescriptionCheckItemDepartmentVo> prescriptionCheckItemDepartmentVoList = prescriptionDao.getAllPrescriptionsByPatientId(patientId);
        System.out.println("检查科室\t\t检查项目\t\t检查结果\t\t检查费用\t\t检查时间");
        prescriptionCheckItemDepartmentVoList.forEach(System.out::println);
    }
}
